package org.micode.demo.db.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.micode.common.helper.I18nMsgHelper;
import org.micode.common.utils.StringExtUtils;

/**
 * 配置参数来源枚举
 *
 * @author: wutianbin
 * @version: v1.0.27
 * @CreateDate: 2021-11-10
 */
@Getter
@RequiredArgsConstructor
public enum ConfigSourceEnum {

    HAND(0,"hand.input","手工录入"),

    DICT(1,"dictionary","从字典选"),

    ID_NAME(2,"id.name","从接口获取ID-NAME"),

    CHOOSE(3,"choose.items","固定值选择"),
    ;

    private final int value;

    private final String code;

    private final String name;

    public static ConfigSourceEnum getByValue(int value) {
        for (ConfigSourceEnum status : ConfigSourceEnum.values()) {
            if (status.value == value) {
                return status;
            }
        }
        return null;
    }

    public static ConfigSourceEnum getByCode(String code) {
        for (ConfigSourceEnum status : ConfigSourceEnum.values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        return null;
    }

    public static boolean findByValue(int value) {
        for (ConfigSourceEnum status : ConfigSourceEnum.values()) {
            if (status.value == value) {
                return true;
            }
        }
        return false;
    }

    public static boolean findByCode(String code) {
        for (ConfigSourceEnum status : ConfigSourceEnum.values()) {
            if (status.code.equals(code)) {
                return true;
            }
        }
        return false;
    }

    public String getName() {
        String ret = I18nMsgHelper.get(this.getClass().getSimpleName() + "." + code);
        if (StringExtUtils.isAnyEmpty(ret)) {
            return name;
        } else {
            return ret;
        }
    }

}
